private static IColorReference ReferenceFromConstructor(IObjectCreationExpression constructorExpression) { var constructedType = constructorExpression.TypeReference?.Resolve().DeclaredElement as ITypeElement; if (constructedType == null) { return(null); } var unityColorTypes = UnityColorTypes.GetInstance(constructedType.Module); if (!unityColorTypes.IsUnityColorType(constructedType)) { return(null); } var arguments = constructorExpression.Arguments; if (arguments.Count < 3 || arguments.Count > 4) { return(null); } Color?color = null; if (unityColorTypes.UnityColorType != null && unityColorTypes.UnityColorType.Equals(constructedType)) { var baseColor = GetColorFromFloatARGB(arguments); if (baseColor == null) { return(null); } color = baseColor.Item1.HasValue ? Color.FromArgb((int)(255.0 * baseColor.Item1.Value), baseColor.Item2) : baseColor.Item2; } else if (unityColorTypes.UnityColor32Type != null && unityColorTypes.UnityColor32Type.Equals(constructedType)) { var baseColor = GetColorFromIntARGB(arguments); if (baseColor == null) { return(null); } color = baseColor.Item1.HasValue ? Color.FromArgb(baseColor.Item1.Value, baseColor.Item2) : baseColor.Item2; } if (color == null) { return(null); } var colorElement = new ColorElement(color.Value); var argumentList = constructorExpression.ArgumentList; return(new UnityColorReference(colorElement, constructorExpression, argumentList, argumentList.GetDocumentRange())); }
private static IColorReference ReferenceFromInvocation(IReferenceExpression qualifier, IReferenceExpression methodReferenceExpression) { var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(methodReferenceExpression); if (invocationExpression == null || invocationExpression.Arguments.IsEmpty) { return(null); } var methodReference = methodReferenceExpression.Reference; var name = methodReference.GetName(); if (!string.Equals(name, "HSVToRGB", StringComparison.Ordinal)) { return(null); } var arguments = invocationExpression.Arguments; if (arguments.Count < 3 || arguments.Count > 4) { return(null); } var color = GetColorFromHSV(arguments); if (color == null) { return(null); } var qualifierType = qualifier.Reference.Resolve().DeclaredElement as ITypeElement; if (qualifierType == null) { return(null); } var unityColorTypes = UnityColorTypes.GetInstance(qualifierType.Module); if (!unityColorTypes.IsUnityColorTypeSupportingHSV(qualifierType)) { return(null); } var colorElement = new ColorElement(color.Value); var argumentList = invocationExpression.ArgumentList; return(new UnityColorReference(colorElement, invocationExpression, argumentList, argumentList.GetDocumentRange())); }
private static IColorReference ReferenceFromProperty(IReferenceExpression qualifier, IReferenceExpression colorQualifiedMemberExpression) { var name = colorQualifiedMemberExpression.Reference.GetName(); var color = UnityNamedColors.Get(name); if (color == null) { return(null); } var qualifierType = qualifier.Reference.Resolve().DeclaredElement as ITypeElement; if (qualifierType == null) { return(null); } var unityColorTypes = UnityColorTypes.GetInstance(qualifierType.Module); if (!unityColorTypes.IsUnityColorTypeSupportingProperties(qualifierType)) { return(null); } var property = colorQualifiedMemberExpression.Reference.Resolve().DeclaredElement as IProperty; if (property == null) { return(null); } var colorElement = new ColorElement(color.Value, name); return(new UnityColorReference(colorElement, colorQualifiedMemberExpression, colorQualifiedMemberExpression, colorQualifiedMemberExpression.NameIdentifier.GetDocumentRange())); }