public DotNetCommandParamData Clone()
        {
            var copy = new DotNetCommandParamData()
            {
                OriginalName = this.OriginalName,
                Name = this.Name,
                OriginalType = this.OriginalType,
                NativeType = this.NativeType,
                DotNetType = this.DotNetType,
                IsEnum = this.IsEnum,
                IsPointer = this.IsPointer,
                IsOutput = this.IsOutput,
                ShouldUseGenerics = this.ShouldUseGenerics,
                ShouldUseRef = this.ShouldUseRef,
                ShouldUseFixed = this.ShouldUseFixed,
                ShouldUseAddressOfOperator = this.ShouldUseAddressOfOperator,
                Description = this.Description
            };

            return copy;
        }
Esempio n. 2
0
		private void TranslateCommands(XmlSpecData spec, DotNetApiData api, Options options)
		{			
			foreach (var specCommand in spec.Commands.Where(x => options.CommandFilter(x)))
			{
				var specFeature = spec.Features.Where(x => x.AddedCommands.Contains(specCommand.Name)).FirstOrDefault();

				var commandData = new DotNetCommandData()
				{
                    IsFromSpec = true,
					OriginalName = specCommand.Name,
					NativeName = this.InflectFunctionNativeName(specCommand.Name, options),
					DotNetName = this.InflectFunctionDotNetName(specCommand.Name, options),
					NativeReturnType = this.InflectNativeReturnType(specCommand)
				};

                if (specFeature != null)
                {
                    commandData.VersionMajor = specFeature.VersionMajor;
					commandData.VersionMinor = specFeature.VersionMinor;
                }

				if (commandData.NativeReturnType == "string")
					commandData.IsUnsafe = true;

				foreach (var specCommandParam in specCommand.Params)
				{
					var functionParamData = new DotNetCommandParamData()
					{
						OriginalName = specCommandParam.Name,
						Name = this.InflectFunctionParamName(specCommandParam.Name),
						OriginalType = specCommandParam.Type,
						NativeType = this.InflectFunctionParamNativeType(specCommandParam),
						DotNetType = this.InflectFunctionParamDotNetType(specCommandParam),
						IsPointer = this.IsTypePointer(specCommandParam.Type),
						IsOutput = this.IsTypeOutput(specCommandParam.Type),
						ShouldUseGenerics = this.ShouldUseGenericsForType(specCommandParam.Type),
                        ShouldUseFixed = this.ShouldUseFixedForParam(specCommandParam),
						ShouldUseAddressOfOperator = this.ShouldUseAddressOfOperatorForParam(specCommandParam)
					};

					if (functionParamData.IsPointer)
						commandData.IsUnsafe = true;

					if (functionParamData.ShouldUseGenerics)
						commandData.ShouldUseGenerics = true;

                    if (functionParamData.IsOutput && functionParamData.DotNetType == "IntPtr")
                    {
                        functionParamData.ShouldUseOut = true;
                    }

					commandData.Params.Add(functionParamData);
				}

				api.Commands.Add(commandData);

                if (options.DocsFolder != null)
                {
                    this.ParseDocs(commandData, options);
                }

                // Create overload which accepts the Enum variant.
                if (specCommand.Params.Any(x => this.IsTypeEnum(x, api)))
                {
                    api.Commands.Add(this.ChangeFunctionParamsToEnums(commandData, specCommand.Params.Where(x => this.IsTypeEnum(x, api))));
                }                
			}

            foreach (var commandData in api.Commands.ToArray())
            {
                var specCommand = spec.Commands.Single(x => x.Name == commandData.OriginalName);

                // Commands which take a pointer and it could be a single element.
                if (specCommand.Params.Any(x => this.ShouldChangeFunctionParamToRefOrOut(x)))
                {
                    api.Commands.Add(this.ChangeFunctionParamsToRefOrOut(commandData, specCommand.Params.Where(x => this.ShouldChangeFunctionParamToRefOrOut(x)).Select(x => x.Name)));
                }

                // Commands which take a pointer and it could be a single element.
                if (specCommand.Params.Any(x => this.ShouldChangeFunctionParamToIntPtr(x)))
                {
                    api.Commands.Add(this.ChangeFunctionParamsToIntPtr(commandData, specCommand.Params.Where(x => this.ShouldChangeFunctionParamToIntPtr(x)).Select(x => x.Name)));
                }
            }

            api.Commands.Sort((x, y) => x.OriginalName != null && y.OriginalName != null ? x.OriginalName.CompareTo(y.OriginalName) : 0);
		}